package com.foreveross.proxyip.application.offer.rest.provider;


import java.util.Collections;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.apache.cxf.jaxrs.ext.ResponseHandler;
import org.apache.cxf.jaxrs.model.OperationResourceInfo;
import org.apache.cxf.message.Message;

/**
 * 
 * @author loudyn
 * 
 */
public class RestResponseFilter implements ResponseHandler {

	public Response handleResponse(Message msg, OperationResourceInfo info, Response resp) {
		Object entity = resp.getEntity();
		if (entity instanceof RestResponse) {
			return resp;
		}

		// create a empty result.
		if (null == entity) {
			entity = Collections.emptyMap();
		}

		RestResponse innerResp = new RestResponse.Builder().ok().message("Everything is ok.").result(entity).build();
		return Response.fromResponse(resp).entity(innerResp).status(Status.OK).build();
	}

}
